package com.lanou.moving.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SearchSingerRoot;
import com.lanou.moving.utils.CircleImageView;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/24.
 */
public class SearchSingerAdapter extends BaseAdapter {
    private Context mcontext;
    private List<SearchSingerRoot.DataEntity> datas;
    private SearchSingerRoot.DataEntity entity;

    public SearchSingerAdapter(Context context, List<SearchSingerRoot.DataEntity> data) {
        mcontext = context;
        datas = data;
    }


    @Override
    public int getCount() {
        return datas != null && datas.size() > 0 ? datas.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return datas != null && datas.size() > 0 ? datas.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mcontext).inflate(R.layout.search_content_singer, null);
            holder = new ViewHolder();
            holder.singer_circle = (CircleImageView) convertView.findViewById(R.id.singer_circle);
            holder.singer_name = (TextView) convertView.findViewById(R.id.singer_name);
            holder.song_num = (TextView) convertView.findViewById(R.id.song_num);
            holder.album_num = (TextView) convertView.findViewById(R.id.album_num);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        entity = (SearchSingerRoot.DataEntity) getItem(position);
        if (entity != null) {
            holder.album_num.setText(entity.getAlbum_num() + " ");
            holder.song_num.setText(entity.getSong_num() + " ");
            holder.singer_name.setText(entity.getSinger_name());
            Picasso.with(mcontext).load(entity.getPic_url()).into(holder.singer_circle);
            holder.singer_circle.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });

        }

        return convertView;
    }

    private class ViewHolder {
        private CircleImageView singer_circle;
        private TextView singer_name, song_num, album_num;
    }
}
